package com.telit.firecommand.controller;

import com.telit.common.entity.DataReturn;
import com.telit.common.enums.ResultCode;
import com.telit.firecommand.service.WebSocketPushMsgLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhouyu
 * @description websocket消息记录接口
 */
@RestController
@RequestMapping("/websocket-push-msg-log")
@Api(tags = "websocket消息记录接口",description = "/websocket-push-msg-log")
public class WebSocketPushMsgLogController {

    @Autowired
    private WebSocketPushMsgLogService webSocketPushMsgLogService;

    @GetMapping("/changeToHasRead")
    @ApiOperation("修改为消息已读")
    public DataReturn changeToHasRead(@RequestParam(required = true) Integer eventType, @RequestParam(required = true) Long eventId){
        if (eventType==null || eventId==null){
            return DataReturn.failure(ResultCode.FORM_PARAMS_CHECK_ERROR);
        }
        webSocketPushMsgLogService.changeToHasRead(eventType,eventId);
        return DataReturn.ok();
    }

    @GetMapping("/queryHasReadMsg")
    @ApiOperation("查询已读消息")
    public DataReturn queryHasReadMsg(@RequestParam(required = true) Integer eventType,@RequestParam(required = true) Long userId){
        List<Long> ids= webSocketPushMsgLogService.queryHasReadMsg(eventType,userId);
        return DataReturn.ok(ids);
    }
}
